package com.zxl.live.screen.screen.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;

import com.zxl.live.screen.R;
import com.zxl.live.screen.screen.ui.fragment.SuiScreenDetailFragment;
import com.zxl.live.screen.screen.ui.helper.data.SuiScreenDataHelper;
import com.zxl.live.screen.ui.widget.ViewPagerFixed;
import com.zxl.live.tools.base.BaseAppCompatActivity;

/**
 * Created by Administrator on 2018/1/9.
 */
public class SuiScreenDetailActivity extends BaseAppCompatActivity implements View.OnClickListener {

    private SuiScreenDataHelper.DataType dataType;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sui_screen_detail);
        dataType = (SuiScreenDataHelper.DataType) getIntent().getSerializableExtra("mDataType");
        ViewPagerFixed viewPagerFixed = (ViewPagerFixed) findViewById(R.id.view_pager);
        viewPagerFixed.setAdapter(new SuiScreenAdapter(getSupportFragmentManager()));
        viewPagerFixed.setCurrentItem(getIntent().getIntExtra("position", 0));
    }

    public static void startSuiScreenDetail(Context context, SuiScreenDataHelper.DataType mDataType, int position) {
        Intent intent = new Intent(context, SuiScreenDetailActivity.class);
        intent.putExtra("position", position);
        intent.putExtra("mDataType", mDataType);
        context.startActivity(intent);
    }

    class SuiScreenAdapter extends FragmentPagerAdapter {

        public SuiScreenAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            SuiScreenDetailFragment fragment = new SuiScreenDetailFragment();
            fragment.setPosition(position, dataType);
            return fragment;
        }

        @Override
        public int getCount() {
            return dataType.getSize();
        }
    }

    @Override
    public void onClick(View v) {
        onBackPressed();
    }
}
